﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace myTravian
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate(textBox1.Text);
        }

        private void getrx()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("name", typeof(System.String));
            dt.Columns.Add("level", typeof(System.String));


            HtmlDocument doc = webBrowser1.Document;
            //HtmlElement village = doc.GetElementById("village_map") as  HtmlElement;
            HtmlElement village = doc.GetElementById("rx") as HtmlElement;
            //HtmlElementCollection sources = village.GetElementsByTagName("img") as HtmlElementCollection;
            HtmlElementCollection sources = village.GetElementsByTagName("area") as HtmlElementCollection;
            HtmlElement img = null;
            string[] htmlAttribute;

            for (int i = 0; i < sources.Count; i++)
            {
                img = sources[i] as HtmlElement;
                //if (!string.IsNullOrEmpty(img.GetAttribute("alt")))
                if (!string.IsNullOrEmpty(img.GetAttribute("title")))
                {
                    //htmlAttribute = img.GetAttribute("alt").Split(' ');
                    htmlAttribute = img.GetAttribute("title").Split(' ');

                    if (htmlAttribute.Length > 2)
                    {
                        DataRow row = dt.NewRow();
                        row["name"] = htmlAttribute[0];
                        row["level"] = htmlAttribute[1] + htmlAttribute[2];
                        dt.Rows.Add(row);
                    }
                }
            }
            traGridView1.SetData(dt);        
        }

        private void button2_Click(object sender, EventArgs e)
        {
            getrx();
        }


        private void getDowntown()
        {
            //map2
            DataTable dt = new DataTable();
            dt.Columns.Add("name", typeof(System.String));
            dt.Columns.Add("level", typeof(System.String));


            HtmlDocument doc = webBrowser1.Document;
            //HtmlElement village = doc.GetElementById("village_map") as  HtmlElement;
            HtmlElement village = doc.GetElementById("map2") as HtmlElement;
            //HtmlElementCollection sources = village.GetElementsByTagName("img") as HtmlElementCollection;
            HtmlElementCollection sources = village.GetElementsByTagName("area") as HtmlElementCollection;
            HtmlElement img = null;
            string[] htmlAttribute;

            for (int i = 0; i < sources.Count; i++)
            {
                img = sources[i] as HtmlElement;
                //if (!string.IsNullOrEmpty(img.GetAttribute("alt")))
                if (!string.IsNullOrEmpty(img.GetAttribute("title")))
                {
                    //htmlAttribute = img.GetAttribute("alt").Split(' ');
                    htmlAttribute = img.GetAttribute("title").Split(' ');

                    if (htmlAttribute.Length > 2)
                    {
                        DataRow row = dt.NewRow();
                        row["name"] = htmlAttribute[0];
                        row["level"] = htmlAttribute[1] + htmlAttribute[2];
                        dt.Rows.Add(row);
                    }
                }
            }
            traGridView2.SetData(dt);        
        }

        private void button3_Click(object sender, EventArgs e)
        {
            getDowntown();
        }

    }
}
